<template>
	<view class="setting-container">
		<common-head title="纠纷上报" :autoBack="true"></common-head>
		<view class="farm-content">
			<view class="form-item required">
				<rh-picker 
				label="纠纷类型" 
				v-model="params.jflx"
				:columns="getDictItem('elyb_jflx')" 
				picker-title="选择纠纷类型" 
				placeholder="请选择纠纷类型">
				</rh-picker>
			</view>
			<view class="form-item" v-if="['02', '03'].includes(params.jflx)">
				<rh-picker
				label="涉及权属纠纷地块" 
				v-model="params.jfdkbm" 
				:columns="cbdkList"
				@change="handleChange($event, 'jfdkbm')"
				picker-title="选择权属纠纷地块"
				placeholder="请选择权属纠纷地块">
				</rh-picker>
			</view>
			<view class="form-item">
				<rh-input 
				label="纠纷情况简要说明" 
				maxlength="500" 
				type="textarea" 
				v-model="params.jfsm">
				</rh-input>
			</view>
		</view>
		<rh-submit-btn ref="submit-btn" text="立即上报" @submit="submit"></rh-submit-btn>
	</view>
</template>

<script>
	import { insertCbjf } from '@/script/api/cbjf/index.js'
	import { listCbdk } from '@/script/api/cbdk/index.js' // 承包地块
	export default {
		data() {
			return {
				params: {},
				dictsList: [
					// 数据字典
					{
						label: "纠纷类型",
						name: "elyb_jflx",
						child: []
					},
				],
				cbdkList: []
			}
		},
		created(){
			let _self = this
			this.initGetDicts()
			this.getCbdkList()
		},
		methods: {
			handleChange(item, name){
				let _self = this
				if(name != 'jfdkbm') return 
				_self.$set(_self.params, 'jfdkmc', item.dkmc)
				_self.$set(_self.params, 'jfhtmjm', item.htmjm)
			},
			getCbdkList(){
				let _self = this
				listCbdk().then(res => {
					_self.cbdkList = (res.data || []).map(i => {
						return {
							htmjm: i.htmjm,
							dkmc: i.dkmc,
							dictLabel: `${i.dkmc}-${i.dkxz}`,
							dictValue: i.dkbm
						}
					})
				})
			},
			getDictItem(name){
				let _self = this
				let dict = _self.dictsList.find(i => i.name == name)
				return dict.child
			},
			submit() {
				let _self = this, el = this.$refs['submit-btn']
				const { jflx, jfdkbm, jfsm } = _self.params
				if(!jflx){
					_self.$attention.noIcon('纠纷类型不能为空')
					return el['submit_loading'] = false
				}
				insertCbjf(_self.params).then(res => {
					_self.$attention.noIcon(res.msg)
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 1500)
				}).finally(() => el['submit_loading'] = false)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.setting-container{
		min-height: 100vh;
		background: #f8f8f8;
		.form-item{
			padding: 30rpx 24rpx 30rpx 54rpx;
			background: #fff;
			position: relative;
			&::before{
				visibility: hidden;
				content: "*";
				position: absolute;
				left: 24rpx;
				top: 55%;
				transform: translateY(-50%);
				color: #dd6161;
			}
			&.required::before{
				visibility: visible;
			}
			.form-label{
				font-size: 26rpx;
				color: #333;
			}
		}
	}
</style>
